#include "StdAfx.h"
#include "Trigger.h"


Trigger::Trigger(void)
{
}


Trigger::~Trigger(void)
{
}

//Checks the requirements fot the trigger
bool Trigger::CheckReq(EntityControl *entity)
{
	if(TriggerRequirements.empty())
		return true;
	
	//bool ret = false;
	for(std::vector<TriggerRequirement*>::iterator i = TriggerRequirements.begin(); i!=TriggerRequirements.end();i++)
	{
		if(!(*i)->CheckReq(entity))
			return false;
	}

	return true;
}



//Fires the trigger
bool Trigger::FireTrigger(EntityControl *entity)
{

	bool ret = false;
	for(std::vector<TriggerAction*>::iterator i = TriggerActions.begin(); i!=TriggerActions.end();i++)
	{
		if((*i)->FireTrigger(entity))
			ret = true;
	}

	return ret;
}


bool Trigger::UseTrigger(EntityControl *entity)
{
	bool res = CheckReq(entity);
	if(!res)
		return false;
	res = FireTrigger(entity);
	return res;
}

void Trigger::addRequiement(TriggerRequirement* req)
{
	TriggerRequirements.push_back(req);
}

void Trigger::addAction(TriggerAction* action)
{
	TriggerActions.push_back(action);
}